import java.util.ArrayList;
import java.util.List;

// 组织组件接口
interface OrganizationComponent {
    void print();
    void add(OrganizationComponent component);
    void remove(OrganizationComponent component);
    OrganizationComponent getChild(int index);
}

// 部门复合类（可以包含其他组件）
class DepartmentComposite implements OrganizationComponent {
    private String name;
    private List<OrganizationComponent> children = new ArrayList<>();

    public DepartmentComposite(String name) {
        this.name = name;
    }

    @Override
    public void print() {
        for (OrganizationComponent component : children) {
            component.print();
        }
    }

    @Override
    public void add(OrganizationComponent component) {
        children.add(component);
    }

    @Override
    public void remove(OrganizationComponent component) {
        children.remove(component);
    }

    @Override
    public OrganizationComponent getChild(int index) {
        if (index >= 0 && index < children.size()) {
            return children.get(index);
        }
        return null;
    }

    public String getName() {
        return name;
    }
}

// 专业叶子类
class MajorLeaf implements OrganizationComponent {
    private String name;

    public MajorLeaf(String name) {
        this.name = name;
    }

    @Override
    public void print() {
        System.out.println(name);
    }

    @Override
    public void add(OrganizationComponent component) {
        throw new UnsupportedOperationException("叶子节点不能添加子节点");
    }

    @Override
    public void remove(OrganizationComponent component) {
        throw new UnsupportedOperationException("叶子节点不能移除子节点");
    }

    @Override
    public OrganizationComponent getChild(int index) {
        throw new UnsupportedOperationException("叶子节点没有子节点");
    }

    public String getName() {
        return name;
    }
}

// 行政单位叶子类
class AdministrativeLeaf implements OrganizationComponent {
    private String name;

    public AdministrativeLeaf(String name) {
        this.name = name;
    }

    @Override
    public void print() {
        System.out.println(name);
    }

    @Override
    public void add(OrganizationComponent component) {
        throw new UnsupportedOperationException("叶子节点不能添加子节点");
    }

    @Override
    public void remove(OrganizationComponent component) {
        throw new UnsupportedOperationException("叶子节点不能移除子节点");
    }

    @Override
    public OrganizationComponent getChild(int index) {
        throw new UnsupportedOperationException("叶子节点没有子节点");
    }

    public String getName() {
        return name;
    }
}

// 客户端代码
public class UniversityOrganization {
    public static void main(String[] args) {
        // 创建教学部门（包含多个专业）
        DepartmentComposite teachingDepartment = new DepartmentComposite("教学部门");
        teachingDepartment.add(new MajorLeaf("计算机科学专业"));
        teachingDepartment.add(new MajorLeaf("通信工程专业"));
        teachingDepartment.add(new MajorLeaf("软件工程专业"));
        teachingDepartment.add(new MajorLeaf("人工智能专业"));

        // 创建行政部门（包含多个行政单位）
        DepartmentComposite administrativeDepartment = new DepartmentComposite("行政部门");
        administrativeDepartment.add(new AdministrativeLeaf("人事处"));
        administrativeDepartment.add(new AdministrativeLeaf("教务处"));

        // 创建教师处（根据表格）
        AdministrativeLeaf teacherOffice = new AdministrativeLeaf("教师处");

        // 创建学校根节点
        DepartmentComposite university = new DepartmentComposite("学校");
        university.add(teacherOffice);        // 教师处
        university.add(administrativeDepartment); // 行政部门
        university.add(teachingDepartment);    // 教学部门

        // 打印所有专业和行政单位
        System.out.println("---学校的专业和行政单位如下：");
        university.print();
    }
}